******************************************************

* Masterfile analyses


******************************************************


set matsize 11000

*Set directory where the folder "replication" is located
cd "~/replication"

*Install programs
ssc install carryforward, replace
ssc install spmap, replace
do "ado/bunch_count/bunch_count.ado"

*Open data
u "data/data_funds.dta", replace


******************************************************

* Figures and Tables in the manuscript

******************************************************


*---------------------------------------------------------------------
*Figure 1 is a diagram - no underlying data.


*---------------------------------------------------------------------
*Figure 2 : Distribution of subsidies before and after 2013 law

	label define new_law 0 "Before 2013 Law" 1 "After 2013 Law", replace
	label values new_law new_law

	 twoway  (histogram y , xmtick(50000(9999)250000, grid ) graphregion(color(white)) bgcolor(white) xline(150001, lcolor(red) lpattern(dash)) ///
			xtitle("Subsidies Distribution (Euros)") legend(label(1 "After 2013 Law") label(2 "Before 2013 Law") position(6) rows(1))   ///
			percent bin(199) lwidth(thin) color(gs8) fintensity(.7) graphregion(color(white)) bgcolor(white) by(new_law, note("")))  
	 graph export "figures/figure2.pdf", as(pdf) replace


*---------------------------------------------------------------------
*Figure 3: Change in subsidies by bin after 2013 Law
*Table 1: Change in subsidies by bin after 2013 Law (Columns 1 and 2)

	preserve
		*Create database at the request-amount (y) year level
		collapse (rawsum) n, by(y_bin year_bando) 
		egen panelvar=group(y_bin)

		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
		
		gen new_law=(year_bando>2013)
		
		*Create just below dummy
		gen justbelow=(y_bin>149000 & y_bin<150001 & y_bin!=.)
		
		su n
		local meandv=round(r(mean),0.01)
		local sd=round(r(sd),0.01)
		
		*Table 1, Col 1
		reghdfe n ib151000.y_bin##new_law i.year_bando, cluster(y_bin) noabs
		outreg2 using "tables/table1", replace keep(150000.y_bin 1.new_law 150000.y_bin#1.new_law 155000.y_bin 155000.y_bin#1.new_law) nocons addtext(Year FE, Yes, City FE, No, Mean DV, `meandv', Sd DV, `sd') tex ctitle("Fully saturated","model")
		
		* Figure 3
		coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 185 "After*250,000")
		graph export "figures/figure3.pdf", as(pdf) replace
		
		*Table 1, Col 2
		reghdfe n i.justbelow##i.new_law i.year_bando, cluster(y_bin) noabs
		outreg2 using "tables/table1", nocons keep(1.justbelow 1.new_law 1.justbelow#1.new_law) addtext(Year FE, Yes, City FE, No, Mean DV, `meandv', Sd DV, `sd') tex ctitle("Bin just below", "vs all others")
		
	restore

*---------------------------------------------------------------------	
*Figure 4: Parallel trends test

	preserve
		*Create database at the request-amount (y) year level
		collapse (rawsum) n, by(y_bin year_bando)
		egen panelvar=group(y_bin)

		tsset panelvar year_bando
		tsfill, full

		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
		
		gen new_law=(year_bando>2013)
	
		*Create just below dummy
		gen justbelow=(y_bin>149000 & y_bin<150001 & y_bin!=.)
		
		label var y_bin "Bin"
		label var year_bando "Y"
		label var justbelow "150k"

		reghdfe n i.justbelow##b2013.year_bando, cluster(y_bin) noabs
		coefplot, vertical keep(1.justbelow#*) xlab(,angle(45)) label yline(0, lcolor(red)) baselevels omitted
		graph export "figures/figure4.pdf", as(pdf) replace
	restore


*---------------------------------------------------------------------
*Figure 5: Change in subsidies after 2013, by mafia and ’Ndrangheta presence (Upper panel)
*Table 1: Change in subsidies by bin after 2013 Law (Column 3)

	preserve
		*Create database at the request-amount (y) year and mafia presence level
		collapse (rawsum) n, by(y_bin year_bando city_mafia)
		
		egen panelvar=group(city_mafia y_bin)

		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward city_mafia y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward city_mafia y_bin, replace
		replace n=0 if n==.
		
		gen new_law=(year_bando>2013)
		
		su n	
		local meandv=round(r(mean),0.01)
		local sd=round(r(sd),0.01)
		
		reghdfe n ib151000.y_bin##i.new_law##i.city_mafia , cluster(y_bin) abs(year_bando)
		outreg2 using "tables/table1",  keep(1.new_law 1.city_mafia 150000.y_bin 150000.y_bin#1.new_law 150000.y_bin#1.city_mafia 1.new_law#1.city_mafia 150000.y_bin#1.new_law#1.city_mafia ) nocons addtext(Year FE, Yes,  City FE, No, Mean DV, `meandv', Sd DV, `sd') tex ctitle("By mafia", "presence")
		
		*Figure  5, upper panel
		coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 185 "After*250,000") name(nomafia, replace) title(No Mafia)
		coefplot, vertical xline(101) keep(*#1.new_law#1.city_mafia) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 185 "After*250,000") name(mafia, replace) title(Mafia)
		graph combine nomafia mafia, ycommon
		graph export "figures/figure5_upper.pdf", as(pdf) replace
	restore

	
*---------------------------------------------------------------------	
*Figure 5: Change in subsidies after 2013, by mafia and ’Ndrangheta presence (Lower panel)

	preserve
		collapse (rawsum) n, by(y_bin year_bando ndrangheta) 
		
		egen id=group(y_bin ndrangheta)
		xtset id year_bando
		tsfill, full
		bys id: carryforward y_bin ndrangheta , replace
		gsort id-year_bando
		bys id: carryforward y_bin ndrangheta , replace
		sort id year_bando
		replace n=0 if n==.
		
		gen new_law=(year_bando>2013)
		
		*Figure 5, lower panel
		reghdfe n i.y_bin##i.new_law##i.ndrangheta, cluster(y_bin) abs(year_bando)
		coefplot, vertical xline(101) keep(*#1.new_law#1.ndrangheta) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 192 "After*250,000") title("Kinship-based organization") name(kinship, replace)
		graph combine nomafia mafia kinship, ycommon col(3)
		graph export "figures/figure5_lower.pdf", as(pdf) replace
	restore
	
*---------------------------------------------------------------------	
*Table 2: How sorting firms differ from other firms

reghdfe delay_end i.justbelow##i.new_law company_life, abs(forma_giuridica cod_comune anno_)
outreg2 using "tables/table2", replace ctitle("Delay", "(months)") keep(1.justbelow 1.new_law 1.justbelow#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) nocons

reghdfe prv i.justbelow##i.new_law  company_life, abs(forma_giuridica cod_comune anno_)   
outreg2 using "tables/table2", ctitle("Private co-", "financing") keep(1.justbelow 1.new_law 1.justbelow#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) nocons

reghdfe mafiasector i.justbelow##i.new_law company_life, abs(forma_giuridica cod_comune anno_)    
outreg2 using "tables/table2", ctitle("Mafia", "sector") keep(1.justbelow 1.new_law 1.justbelow#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) nocons

reghdfe Nomafiasector i.justbelow##i.new_law company_life, abs(forma_giuridica cod_comune anno_)    
outreg2 using "tables/table2", ctitle("Not mafia", "sector") keep(1.justbelow 1.new_law 1.justbelow#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) nocons

reghdfe age2 i.justbelow##i.new_law, abs(forma_giuridica cod_comune anno_)  
outreg2 using "tables/table2", ctitle("Created 2yr", "before call") keep(1.justbelow 1.new_law 1.justbelow#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, No) nocons

reghdfe boardmafioso i.justbelow##i.new_law company_life, abs(forma_giuridica cod_comune anno_)   
outreg2 using "tables/table2", ctitle("BoD from", "mafia area") keep(1.justbelow 1.new_law 1.justbelow#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) nocons

reghdfe corruption i.justbelow##i.new_law company_life, abs(forma_giuridica cod_comune anno_)   
outreg2 using "tables/table2", ctitle("Corruption") keep(1.justbelow 1.new_law 1.justbelow#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) nocons

reghdfe slowadmin i.justbelow##i.new_law company_life, abs(forma_giuridica cod_comune anno_)   
outreg2 using "tables/table2",  ctitle("Inefficiency") keep(1.justbelow 1.new_law 1.justbelow#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) nocons

*---------------------------------------------------------------------	
*Table 3: Characteristics of business owners (alleged figureheads)

preserve

	u "data/data_figureheads.dta", clear

	reghdfe concentration new_law##city_mafia##above, abs(forma_giuridica cod_comune anno_)   
	outreg2 using "tables/table3", replace keep(1.above 1.city_mafia  1.new_law 1.new_law#1.city_mafia 1.new_law#1.city_mafia#1.above 1.city_mafia#1.above 1.new_law#1.above) tex addtext(City FE, Yes, Institution FE, Yes, Year FE, Yes) nocons
				
	reghdfe old new_law##city_mafia##above, abs(forma_giuridica cod_comune anno_)   
	outreg2 using "tables/table3",  keep(1.above 1.city_mafia  1.new_law 1.new_law#1.city_mafia 1.new_law#1.city_mafia#1.above 1.city_mafia#1.above 1.new_law#1.above) tex addtext(City FE, Yes, Institution FE, Yes, Year FE, Yes) nocons
						
	reghdfe boardmafioso new_law##city_mafia##above, abs(forma_giuridica cod_comune anno_)   
	outreg2 using "tables/table3", keep(1.above 1.city_mafia  1.new_law 1.new_law#1.city_mafia 1.new_law#1.city_mafia#1.above 1.city_mafia#1.above 1.new_law#1.above) tex addtext(City FE, Yes, Institution FE, Yes, Year FE, Yes) nocons
			
restore



******************************************************
******************************************************

* Figures and Tables in Appendix

******************************************************
******************************************************


*---------------------------------------------------------------------	
*Table A1: Descriptive statistics

preserve
		*Create database at the request-amount (y) year level
		collapse (rawsum) n, by(y_bin year_bando) 
		egen panelvar=group(y_bin)

		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace

		replace n=0 if n==.
		label var n "Number of subsidies by bin"
		estpost sum n
		esttab using "Tables/tableA1.tex", cell((N mean(fmt(%9.3f)) sd(fmt(%9.3f)) min(fmt(%9.3f)) max(fmt(%9.3f)))) nonumber nomtitle replace label

restore

estpost sum y justbelow city_mafia delay_end prv mafiasector Nomafiasector company_life age2 boardmafioso corruption slowadmin wtot_debt_bank wtot_tot_debt tot_cashratio tot_cash tot_roa
esttab using "Tables/tableA1.tex", cell((N mean(fmt(%9.3f)) sd(fmt(%9.3f)) min(fmt(%9.3f)) max(fmt(%9.3f)))) nonumber nomtitle label append


preserve

	u "data/data_figureheads.dta", clear
	estpost sum concentration old boardmafioso
	esttab using "Tables/tableA1.tex", cell((N mean(fmt(%9.3f)) sd(fmt(%9.3f)) min(fmt(%9.3f)) max(fmt(%9.3f)))) nonumber nomtitle label append

restore

*---------------------------------------------------------------------	
*Figure A.1: Distribution of subsidies by sector and awarding institutions

	graph hbar (count), over(sector, sort(1) descending) intensity(50) ytitle("") name(sector, replace)
	graph hbar (count), over(instit, sort(1) descending) intensity(50) ytitle("") name(instit, replace)
	graph combine sector instit, col(1)
	graph export "figures/figureA1.pdf", as(pdf) replace
	
	
*---------------------------------------------------------------------	
*Table A.2: Number of subsidies per year in full and matched databas

	tab year_bando n, column
	 
	 preserve
		u "data/data_opencoesione.dta", clear
		tab year_bando n, column
	restore

*---------------------------------------------------------------------	
*Figure A.2: Presence of mafias (as defined in Section 4) and sorting at the threshold

preserve
	*collapse at the coordinate level
	collapse (rawsum) justbelow city_mafia, by(id x_cc y_cc)
	
	replace justbelow=0 if justbelow==.
	replace city_mafia=1 if city_mafia>1 & city_mafia!=.
	*A2 right
	spmap justbelow using "data/city-coord.dta", id(id) legend(off) osize(vvvthin vvvthin) fcolor(white blue) name(justbelow, replace)
	*A2 left
	spmap city_mafia using "data/city-coord.dta", id(id) legend(off) osize(vvvthin vvvthin) fcolor(white red) name(citymafia, replace)
	graph combine citymafia justbelow
	graph export "figures/figureA2.pdf", replace
restore


*---------------------------------------------------------------------	
*Figure B3: (left) Full sample from OpenCoesione, main (right) Full sample, only 2015 treated.

preserve
	u "data/data_opencoesione", clear
	collapse (rawsum) n, by(y_bin year_bando) 
		egen panelvar=group(y_bin)

		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
		
		gen new_law=(year_bando>2013)
		
		reghdfe n ib151000.y_bin##new_law, cluster(y_bin) abs(year_bando)
		coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 185 "After*250,000")
		graph export "figures/figureB3_left.pdf", as(pdf) replace
restore


preserve
	u "data/data_opencoesione", clear
	collapse (rawsum) n, by(y_bin year_bando) 
		egen panelvar=group(y_bin)

		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
		
		gen new_law=(year_bando>2014)
		
		reghdfe n ib151000.y_bin##new_law, cluster(y_bin) abs(year_bando)
		coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 185 "After*250,000")
		graph export "figures/figureB3_right.pdf", as(pdf) replace
restore

*---------------------------------------------------------------------	
*Figure B4: Full sample from Opencoesione with bin size modified to 2,000 (left) 
*and 500 euros (center). On the right, placebo for dissolved city councils.


preserve
	u "data/data_opencoesione", clear
		egen y_bin2000 = cut(y), at(50000(2000)250000)
		drop y_bin
		rename y_bin2000 y_bin
		collapse (rawsum) n, by(y_bin year_bando) 
		egen panelvar=group(y_bin)

		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
		gen new_law=(year_bando>2013)
		
		reghdfe n ib151000.y_bin##new_law, cluster(y_bin) abs(year_bando)
		coefplot, vertical xline(51) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 51 "After*150,000 Euro" 95 "After*250,000")
		graph export "figures/figureB4_left.pdf", as(pdf) replace
restore

preserve
	u "data/data_opencoesione", clear
		egen y_bin500 = cut(y), at(50000(500)250000)
		drop y_bin
		rename y_bin500 y_bin
		collapse (rawsum) n, by(y_bin year_bando) 
		egen panelvar=group(y_bin)

		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
		gen new_law=(year_bando>2013)
		
		reghdfe n ib151000.y_bin##new_law, cluster(y_bin) abs(year_bando)
		coefplot, vertical xline(200) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 200 "After*150,000 Euro" 350 "After*250,000")
		graph export "figures/figureB4_center.pdf", as(pdf) replace
restore

preserve
	u "data/data_placebo_opencoesione.dta", clear
	reghdfe n y_bin##new_law , cluster(y_bin) abs(year_bando)
	coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 170 "After*250,000")
	graph export "figures/figureB4_right.pdf", as(pdf) replace
restore

*---------------------------------------------------------------------	
*Figure B5: Full sample of observations from OpenCoesione, (left) mafia vs no mafia presence (right) ’Ndrangheta vs no ’Ndrangheta.

	preserve
		u "data/data_opencoesione", clear
		collapse (rawsum) n, by(y_bin year_bando city_mafia)
		
		egen panelvar=group(city_mafia y_bin)

		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward city_mafia y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward city_mafia y_bin, replace
		replace n=0 if n==.
		gen new_law=(year_bando>2013)
		
		su n	
		local meandv=round(r(mean),0.01)
		local sd=round(r(sd),0.01)
		
		reghdfe n ib151000.y_bin##new_law##i.city_mafia i.year_bando, cluster(y_bin) noabs

		coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 192 "After*250,000") name(nomafia, replace) title(No Mafia)
		coefplot, vertical xline(101) keep(*#1.new_law#1.city_mafia) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 192 "After*250,000") name(mafia, replace) title(Mafia)
		graph combine nomafia mafia, ycommon
		graph export "figures/figureB5_left.pdf", as(pdf) replace
	restore
	
	preserve
		u "data/data_opencoesione", clear
		collapse (rawsum) n, by(y_bin year_bando ndrangheta) 
		egen id=group(y_bin ndrangheta)
		xtset id year_bando
		tsfill, full
		
		bys id: carryforward y_bin ndrangheta , replace
		gsort id-year_bando
		bys id: carryforward y_bin ndrangheta , replace
		sort id year_bando
		replace n=0 if n==.
		gen new_law=(year_bando>2013)
		
		*Figure 5, lower panel
		reghdfe n i.y_bin##i.new_law##i.ndrangheta, cluster(y_bin) abs(year_bando)
		coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 185 "After*250,000") name(nokinship, replace) title("No Kinship-based")
		coefplot, vertical xline(101) keep(*#1.new_law#1.ndrangheta) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 185 "After*250,000") title("Kinship-based organization") name(kinship, replace)
		graph combine nokinship kinship, ycommon col(3)
		graph export "figures/figureB5_right.pdf", as(pdf) replace
	restore
	
*---------------------------------------------------------------------	
*Figure B6: Distribution of subsidies before and after 2013 law - including subsidies below 50,000 euros

preserve
	u "data/data_below50000.dta", clear
	label define new_law 0 "Before 2013 Law" 1 "After 2013 Law"
	label values new_law new_law
	twoway (histogram y, xmtick(50000(9999)250000, grid) xline(150001 , lpattern(dash)) xtitle("Subsidies Distribution (Euros)") ///
		legend(label(1 "After 2013 Law") label(2 "Before 2013 Law") position(6) rows(1)) graphregion(color(white)) percent bin(199) ///
		lwidth(thin) color(gs8) fintensity(.8) by(new_law, note(""))	)
	graph export "figures/figureB6.pdf", replace
restore


*---------------------------------------------------------------------	
*Figure B7: Distribution of subsidies before and after 2013 law - by areas with/without ’Ndrangheta presence


	label define new_law 0 "Before 2013 Law" 1 "After 2013 Law", replace
	label values new_law new_law
	
	twoway (histogram y, xmtick(50000(9999)250000, grid) xline(150001 , lpattern(dash)) xtitle("Subsidies Distribution (Euros)") ///
	legend(label(1 "After 2013 Law") label(2 "Before 2013 Law") position(6) rows(1)) graphregion(color(white)) percent bin(199) ///
	lwidth(thin) color(gs8) fintensity(.8) name("mafiano1", replace), if ndrangheta==0,by(new_law, note(""))  title("No 'Ndrangheta")  )
									
	twoway (histogram y, xmtick(50000(9999)250000, grid) xline(150001 , lpattern(dash)) xtitle("Subsidies Distribution (Euros)") ///
	legend(label(1 "After 2013 Law") label(2 "Before 2013 Law") position(6) rows(1)) graphregion(color(white)) percent bin(199) ///
	lwidth(thin) color(gs8) fintensity(.8) name("mafiasi1", replace), if ndrangheta==1,by(new_law, note(""))  title("Yes 'Ndrangheta")  )		

	graph combine mafiano1 mafiasi1,  ycommon	xcommon rows(2)			
	graph export "figures/figureB7.pdf", replace
					
*---------------------------------------------------------------------	
*Figure B8: Distribution of subsidies before and after 2013 law - by mafia/no mafia economic sectors, following the definition in Section 5.3
				
	twoway (histogram y, xmtick(50000(9999)250000, grid) xline(150001 , lpattern(dash)) xtitle("Subsidies Distribution (Euros)") ///
	legend(label(1 "After 2013 Law") label(2 "Before 2013 Law") position(6) rows(1)) graphregion(color(white)) percent bin(199) ///
	lwidth(thin) color(gs8) fintensity(.8) name("nomafiasector", replace), if mafiasector==0, by(new_law, note("")) title("No Mafia"))

	twoway (histogram y, xmtick(50000(9999)250000, grid) xline(150001 , lpattern(dash)) xtitle("Subsidies Distribution (Euros)") ///
	legend(label(1 "After 2013 Law") label(2 "Before 2013 Law") position(6) rows(1)) graphregion(color(white)) percent bin(199) ///
	lwidth(thin) color(gs8) fintensity(.8) name("mafiasector", replace), if mafiasector==1, by(new_law, note("")) title("Yes Mafia"))
					
	graph combine nomafiasector mafiasector,  ycommon rows(2)   graphregion(color(white))
	graph export "figures/figureB8.pdf", replace



*---------------------------------------------------------------------	
* Figure D9: Bunching with a kink

preserve
		*Create database at the request-amount (y) year level
		collapse (rawsum) n, by(y_bin new_law) 
		*fill holes in y_bin (e.g. 130100,(nothing) ,130300) using tsfill
		tsset new_law y_bin, delta(1000) 
		drop if y_bin==.
		tsfill, full
		replace n=0 if n==.
		egen y=group(y_bin)	
		label var y "Bin values"
		label var new_law "Antimafia Law"
		
		cap bunch_count y n if new_law==0, bpoint(101) binwidth(1) plot(1) nboot(1000) 
		graph save "figures/figureD9pre.gph", replace
		cap bunch_count y n if new_law==1, bpoint(101) binwidth(1) plot(1) nboot(1000) 
		graph save "figures/figureD9post.gph", replace

		graph combine "figures/figureD9pre.gph" "figures/figureD9post.gph", ycommon
		graph export "figures/figureD9_a.pdf", as(pdf) replace
		graph erase "figures/figureD9pre.gph" 
		graph erase "figures/figureD9post.gph"

restore


*---------------------------------------------------------------------	
* Figure E10: Change in subsidies by bin after 2013 Law, Region and Year FE

preserve
	collapse (rawsum) n, by(y_bin year_bando new_law den_regione)

	egen id=group(y_bin den_regione)
	tsset id year_bando
	tsfill, full
	bys id: carryforward y_bin, replace
	gsort id-year_bando
	bys id: carryforward y_bin, replace
	replace n=0 if n==.
	egen region=group(den_regione)

	reghdfe n ib151000.y_bin##i.new_law, cluster(y_bin) abs(region year_bando)
	coefplot, vertical xline(101) keep(*#1.new_law) drop(248000.y_bin#1.new_law) msize(medsmall) ytitle("Change N Subsidies") ///
			scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 170 "After*250,000")
	graph export "figures/figureE10.pdf", replace as(pdf)
restore

*---------------------------------------------------------------------	
* Figure E11: (a) Post = After 2014 (b) Bin 2000 euro size

preserve
		*Create database at the request-amount (y) year level
		collapse (rawsum) n, by(y_bin year_bando) 
		
		egen panelvar=group(y_bin)
		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
		
		*Gen new_law2014
		gen new_law2014=(year_bando>2014)
		
		*Create just below dummy
		gen justbelow=(y_bin>149000 & y_bin<150001 & y_bin!=.)
		
		
		reghdfe n ib151000.y_bin##new_law2014, cluster(y_bin) abs(year_bando)
		coefplot, vertical xline(101) keep(*#1.new_law2014) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 190 "After*250,000")
		graph export "figures/figureE11_left.pdf", as(pdf) replace
restore

preserve
		*create bins of 2000 euros size
		gen y_bin2000=y_bin
		forval i=50(2)250 {
		replace y_bin2000=`i'000 if y_bin>`=`i' - 2'000 & y_bin<`i'001
		}
		collapse (rawsum) n, by(y_bin2000 year_bando new_law) 
		rename y_bin2000 y_bin
		
		egen panelvar=group(y_bin)
		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
		
		*Create just below dummy
		gen justbelow=(y_bin>149000 & y_bin<150001 & y_bin!=.)
		
		
		reghdfe n ib151000.y_bin##new_law, cluster(y_bin) abs(year_bando)
		coefplot, vertical xline(51) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 51 "After*150,000 Euro" 90 "After*250,000")
		graph export "figures/figureE11_right.pdf", as(pdf) replace
restore

*---------------------------------------------------------------------	
* Figure E12: (c) Bin 500 euro (d) Bin 100 euro

preserve
		*create bins of 500 euros size
		egen y_bin500 = cut(y), at(50000(500)250000)
		collapse (rawsum) n, by(y_bin500 year_bando) 
		rename y_bin500 y_bin
		gen new_law=(year_bando>2013)
		
		egen panelvar=group(y_bin)
		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
		
		*Create just below dummy
		gen justbelow=(y_bin>149000 & y_bin<150001 & y_bin!=.)
		
		
		reghdfe n ib151000.y_bin##new_law, cluster(y_bin) abs(year_bando)
		coefplot, vertical xline(196) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 196 "After*150,000 Euro" 300 "After*250,000")
		graph export "figures/figureE12_left.pdf", as(pdf) replace
restore

preserve
		*create bins of 100 euros size
		egen y_bin100 = cut(y), at(50000(100)250000)
		collapse (rawsum) n, by(y_bin100 year_bando) 
		rename y_bin100 y_bin
		keep if y_bin>100000 & y_bin<200000
		gen new_law=(year_bando>2013)
		
		egen panelvar=group(y_bin)
		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
	
		gen justbelow=(y_bin>149000 & y_bin<150001 & y_bin!=.)
		
		reghdfe n ib151000.y_bin##new_law, cluster(y_bin) abs(year_bando)
		coefplot, vertical xline(250) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*100,000" 250 "After*150,000 Euro" 400 "After*200,000")
		graph export "figures/figureE12_right.pdf", as(pdf) replace
restore


*---------------------------------------------------------------------	
* Figure E13: (left) Change reference category (right) Remove years fixed effects

preserve
		collapse (rawsum) n, by(y_bin year_bando new_law) 
		
		egen panelvar=group(y_bin)
		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
		
		*Create just below dummy
		gen justbelow=(y_bin>149000 & y_bin<150001 & y_bin!=.)
		
		reghdfe n ib50000.y_bin##new_law, cluster(y_bin) abs(year_bando)
		coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 170 "After*250,000")
		graph export "figures/figureE13_left.pdf", as(pdf) replace
restore

preserve
		collapse (rawsum) n, by(y_bin year_bando new_law) 
		
		egen panelvar=group(y_bin)
		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace
		replace n=0 if n==.
		
		*Create just below dummy
		gen justbelow=(y_bin>149000 & y_bin<150001 & y_bin!=.)
		
		reghdfe n ib151000.y_bin##new_law, cluster(y_bin) noabs
		coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 170 "After*250,000")
		graph export "figures/figureE13_right.pdf", as(pdf) replace
restore



*---------------------------------------------------------------------
*Figure E14: (left) Drop 2013 (right) all values of subsidies
	preserve
			collapse (rawsum) n, by(y_bin year_bando new_law) 
			
			egen panelvar=group(y_bin)
			tsset panelvar year_bando
			tsfill, full
			bys panelvar: carryforward y_bin, replace
			gsort panelvar-year_bando
			bys panelvar: carryforward y_bin, replace
			replace n=0 if n==.
			
			drop if year_bando==2013
			
			*Create just below dummy
			gen justbelow=(y_bin>149000 & y_bin<150001 & y_bin!=.)
			
			reghdfe n ib151000.y_bin##new_law, cluster(y_bin) abs(year_bando)
			coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 170 "After*250,000")
			graph export "figures/figureE14_left.pdf", as(pdf) replace
	restore

	preserve
		u "data/data_below50000.dta", clear
		
		collapse (rawsum) n, by(y_bin year_bando new_law) 
		egen panelvar=group(y_bin)

		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward y_bin, replace

		replace n=0 if n==.
		
		*Create just below dummy
		gen justbelow=(y_bin>149000 & y_bin<150001 & y_bin!=.)
		
		su n
		local meandv=round(r(mean),0.01)
		local sd=round(r(sd),0.01)
		
		reghdfe n ib151000.y_bin##new_law i.year_bando, cluster(y_bin) noabs
		coefplot, vertical xline(146) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*5,000" 146 "After*150,000 Euro" 220 "After*250,000")
		graph export "figures/figureE14_right.pdf", as(pdf) replace
	restore

*---------------------------------------------------------------------	
* Figure E15: (left) City dissolved due to mafia (right) Agricultural funds

preserve
	u "data/data_placebo.dta", clear
	reghdfe n y_bin##new_law , cluster(y_bin) abs(year_bando)
	coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 170 "After*250,000")
	graph export "figures/figureE15_left.pdf", as(pdf) replace
restore

* Agricultural funds
	
preserve
	u  "data/data_agea.dta", clear

	drop if y==.
	keep if y>49999 & y<250001
	gen n=1	
	gen y_bin=y
	forval i=51/250 {
		replace y_bin=`i'000 if y>`=`i' - 1'000 & y<`i'001
	}

	*Create database at the request-amount (y) month-year (date_monthly) level
	collapse (rawsum) n, by(y_bin year_bando)
	
	drop if year_bando==.

	egen panelvar=group(y_bin)
	tsset panelvar year_bando
	tsfill, full
	bys panelvar: carryforward y_bin, replace
	gsort panelvar-year_bando
	bys panelvar: carryforward y_bin, replace
	replace n=0 if n==.
	gen new_law=year_bando>2013
	
	label define new_law 0 "Before 2013" 1 "After 2013" , modify
	label values new_law new_law
	label var y_bin "Bin"

	reghdfe n y_bin##new_law , cluster(y_bin) abs(year_bando)
	coefplot, vertical xline(101) keep(*#1.new_law) msize(medsmall) ytitle("Change N Subsidies") scheme(plottig) xlabel(1 "After*50,000" 101 "After*150,000 Euro" 170 "After*250,000")
	graph export "figures/figureE15_right.pdf", as(pdf) replace
restore	
	
*---------------------------------------------------------------------	
* Table F4: Evidence of displacement: Change in subsidies above the threshold after 2013 Law

	preserve
		collapse (rawsum) n, by(y_bin year_bando new_law city_mafia)
		
		egen panelvar=group(city_mafia y_bin)
		tsset panelvar year_bando
		tsfill, full
		bys panelvar: carryforward city_mafia y_bin, replace
		gsort panelvar-year_bando
		bys panelvar: carryforward city_mafia y_bin, replace
		replace n=0 if n==.
		
		gen above=(y_bin>150000 & y_bin!=.)
		gen justabove=(y_bin>150000 & y_bin<160001 & y_bin!=.)
		
		su n
		local meandv=round(r(mean),0.01)
		local sd=round(r(sd),0.01)
		
		*Table F4, Col 1
		reghdfe n i.above##i.new_law##i.city_mafia, cluster(y_bin) abs(year_bando)
		outreg2 using "tables/tableF4", replace nocons keep(1.above 1.new_law 1.city_mafia 1.above#1.new_law 1.above#1.city_mafia 1.new_law#1.city_mafia 1.above#1.new_law#1.city_mafia)  addtext(Year FE, Yes, City FE, No, Mean DV, `meandv', Sd DV, `sd') tex 
	
		reghdfe n i.justabove##i.new_law##i.city_mafia, cluster(y_bin) abs(year_bando)
		outreg2 using "tables/tableF4", nocons nor2 keep(1.justabove 1.new_law 1.city_mafia 1.justabove#1.new_law 1.justabove#1.city_mafia 1.new_law#1.city_mafia 1.justabove#1.new_law#1.city_mafia)  addtext(Year FE, Yes, City FE, No, Mean DV, `meandv', Sd DV, `sd') tex 
	restore
	
*---------------------------------------------------------------------	
* Table G5: Subsidies by bin after 2013 – Balance sheet outcomes

cap erase "tables/tableG5.tex"
cap erase "tables/tableG5.txt"

local depvar wtot_debt_bank wtot_tot_debt tot_cashratio tot_cash tot_roa   
foreach y in `depvar' {
	reghdfe `y' i.justbelow##i.new_law company_life, abs(forma_giuridica  cod_comune anno_)
	outreg2 using "tables/tableG5", nocons nor2 keep(1.justbelow 1.new_law 1.justbelow#1.new_law) tex addtext(City FE, Yes, Institution FE, Yes, Year FE, Yes, Years of Activity, Yes)
}

*---------------------------------------------------------------------	
* Table G6: Subsidies by bin after 2013  - Just below compared to just above (Robustness)

*Delay, 
reghdfe delay_end justbelow_orjustabove##new_law company_life, abs(forma_giuridica cod_comune anno_)
outreg2 using "tables/tableG6", replace keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) label
reghdfe delay_end justbelow_orjustabove##new_law, noabs 
outreg2 using "tables/tableG6", keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, No, Institution Type FE, No, Year FE, No, Years of Activity, No) label

*Cofinancing, 
reghdfe prv justbelow_orjustabove##new_law company_life, abs(forma_giuridica cod_comune anno_)
outreg2 using "tables/tableG6", keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) label
reghdfe prv justbelow_orjustabove##new_law, noabs
outreg2 using "tables/tableG6", keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, No, Institution Type FE, No, Year FE, No, Years of Activity, No) label

*Mafia Sectors, 
reghdfe mafiasector justbelow_orjustabove##new_law company_life, abs(forma_giuridica cod_comune anno_)
outreg2 using "tables/tableG6", keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) label
reghdfe mafiasector justbelow_orjustabove##new_law, noabs  
outreg2 using "tables/tableG6", keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, No, Institution Type FE, No, Year FE, No, Years of Activity, No) label

*Nomafia Sectors, 
reghdfe Nomafiasector justbelow_orjustabove##new_law  company_life, abs(forma_giuridica cod_comune anno_)
outreg2 using "tables/tableG6", keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) label
reghdfe Nomafiasector justbelow_orjustabove##new_law, noabs  
outreg2 using "tables/tableG6", keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, No, Institution Type FE, No, Year FE, No, Years of Activity, No) label
 
*1 year of life, 
reghdfe age2 justbelow_orjustabove##new_law, abs(forma_giuridica cod_comune anno_)
outreg2 using "tables/tableG6", keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) label
reghdfe age2 justbelow_orjustabove##new_law, noabs 
outreg2 using "tables/tableG6", keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, No, Institution Type FE, No, Year FE, No, Years of Activity, No) label

*BOD mafia
reghdfe boardmafioso justbelow_orjustabove##new_law company_life, abs(forma_giuridica cod_comune anno_)
outreg2 using "tables/tableG6", keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, Yes, Institution Type FE, Yes, Year FE, Yes, Years of Activity, Yes) label
reghdfe boardmafioso justbelow_orjustabove##new_law, noabs
outreg2 using "tables/tableG6", keep(1.justbelow_orjustabove 1.new_law 1.justbelow_orjustabove#new_law) tex addtext(City FE, No, Institution Type FE, No, Year FE, No, Years of Activity, No) label

*---------------------------------------------------------------------	
* Table H7: Optimal threshold

*	see excel file in "tables" folder for simulation

